
/**
 * @param {object} file
 *
 */
export function fileRead(file) {
  var wrap = []
  var isList = file.length > 1 // 判断是文件列表还是单文件
  return new Promise(function(resolve, reject) {
    console.log(file.length)
    if (isList) {
      for (let i = 0; i < file.length; i++) {
        const reader = new FileReader()
        reader.readAsDataURL(file[i])
        reader.onload = function(e) {
          wrap.push(this.result)
          if (i + 1 === file.length) {
            resolve(wrap)
          }
        }
      }
    } else {
      const reader = new FileReader()
      reader.readAsDataURL(file[0])
      reader.onload = function(e) {
        resolve(this.result)
      }
    }
  })
}
